package esempi.graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * This example shows how to open use an Image into a Graphics. 
 * 
 * @author Alessandro Martinelli
 */
public class Esempio04Images {
	
	public static void main(String[] args) {
		JFrame frame1=new JFrame();
		frame1.setSize(270,270);
		frame1.setTitle("java.awt.Graphics");
		frame1.getContentPane().add(new ExamplePanel());
		frame1.setVisible(true);
		frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
	}
	
	public static class ExamplePanel extends JPanel{
		
		private BufferedImage image1;

		public ExamplePanel() {
			try {
				image1=ImageIO.read(new File("images/text.png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		@Override
		protected void paintComponent(Graphics graphics) {
			super.paintComponent(graphics);
		
			Graphics2D graphics2=(Graphics2D)graphics;
			graphics2.setBackground(Color.WHITE);

			graphics2.drawImage(image1,10,10, null);
		}
	}

}
